﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Mad.Nug.Rss;

namespace Mad.Nug
{
    public partial class MainPage : PhoneApplicationPage
    {
        private RssReader _DatosRss = new RssReader();

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                if (App.HaveConnection())
                {
                    _DatosRss.rssSource = @"http://madriddotnet.wordpress.com/feed/";
                    _DatosRss.LoadRssItems();
                    lstContent.SelectedIndex = -1;
                }
                else
                {
                    MessageBox.Show("No dispone de una conexión de datos en estos momentos, cierre la aplicación y pruebe de nuevo más tarde.");
                    progressBar.Visibility = Visibility.Collapsed;
                }
            }
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            StartAnimation.Begin();
            this.DataContext = _DatosRss;
        }
    }
}